package Components
{
	import flash.text.TextField;
	import flash.text.TextFormat;
	import nl.jorisdormans.phantom2D.cameras.Camera;
	import nl.jorisdormans.phantom2D.core.Layer;
	/**
	 * ...
	 * @author Sebastiaan
	 */
	public class ScoreDisplay extends Layer
	{
		private var textField : TextField;
		private var background : uint;
		public static var score : int; 				//counts the score
		public static var scoring : Boolean;
		
		public function ScoreDisplay(color:uint=0xffffff, font:String = "Arial", size:int = 12, background:uint = 0x000000) 
		{
			super();
			textField = new TextField();
			textField.defaultTextFormat = new TextFormat(font, size, color);
			textField.text = "Score";
			textField.width = size * 10;
			textField.height = size * 1.5;
			this.background = background;
			sprite.addChild(textField);
			
			scoring = true;
		}
		
		override public function update(elapsedTime:Number):void
		{
			super.update(elapsedTime);
			if (scoring)
			{
				textField.text = "Score: " + score++;
			}
		}
		
		override public function render(camera:Camera):void 
		{
			super.render(camera);
			sprite.graphics.beginFill(background, 0.5);
			sprite.graphics.drawRect(0, 0, textField.width, textField.height);
			sprite.graphics.endFill();
		}
	}
}